Page({
  /**
   * 页面的初始数据
   */
  data: {
    show: false,
    show1: false,
    show2: false,
    options: [],
    fieldValue: '',
    fieldValue1: '',
    fieldValue2: '',
    cascaderValue: '',
    date:'',
    list:[]
  },
  onClose2() {
    this.setData({ show2: false });
  },
  formatDate(date) {
    date = new Date(date);
    return `${date.getFullYear()}/${date.getMonth() + 1}/${date.getDate()}`;
  },
  onDisplay() {
    this.setData({ show2: true });
  },
  onConfirm(event) {
    this.setData({
      show2: false,
      date: this.formatDate(event.detail),
    });
  },
  but01(){
    wx.switchTab({
      url: '/pages/zhuye/zhuye'
    })
  },
  onClick() {
    this.setData({
      show: true,
    });
  },
  selectType(e){
    this.setData({
      show1: false,
      fieldValue1:e._relatedInfo.anchorTargetText
    })
    console.log(e._relatedInfo.anchorTargetText);
    console.log(e);
  },
  onClick1(){
    this.setData({
      show1: true,
    });
  },
  onClick2(){
    this.setData({
      show2: true,
    });
  },
  onClose1(){
    this.setData({
      show1: false,
    });
  },
  onClose() {
    this.setData({
      show: false,
    });
  },

  onFinish(e) {
    const { selectedOptions, value } = e.detail;
    const fieldValue = selectedOptions
        .map((option) => option.text || option.grade)
        .join('/');
    this.setData({
      show: false,
      fieldValue,
      cascaderValue: value,
    })
  },
  click1(){
    wx.switchTab({
      url: '/pages/zhuye/zhuye'
    })
  },
  but02(){
    console.log(this.data.fieldValue1.trim());
    wx.navigateTo({
      url: `/pages/chazhao/chazhao?grade=${this.data.fieldValue}&kind=${this.data.fieldValue1.trim()}`
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
  const that=this;
wx.request({
  url: 'http://localhost:8080/zixunshi/list',
  success(res){
    const formattedData = res.data.map(item => ({
      text: item.grade, 
      id: item.id,
      kind: item.kind,
      originalItem: item 
    }));
    console.log(res.data);
    console.log(formattedData);
    that.setData({
      options: [...formattedData]
    });
  }
})
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})